package uk.ac.aber.paws.server.core;


import java.util.logging.Level;
import java.util.logging.Logger;
import uk.ac.aber.paws.server.config.ConfigManager;
import uk.ac.aber.paws.server.db.DBLocalCallQueue;
import uk.ac.aber.paws.server.remoteinstall.ProcessInstallRequests;
import uk.ac.aber.paws.server.remoteinstall.RemoteInstallOperations;

/**
 * @author Rob Johnson, Aberystwyth University
 * @email rob.johnson@aber.ac.uk
 * @date 21st May 2012
 * 
 * PAWSInstaller.java
 * 
 * This is the main class for the PAWS installer application. This class runs as its own entity processing
 * requests from a database and acting on the request by performing the relevant installation to the client.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class PAWSInstaller {

	public static Logger LOG_FILE;
	public static String domain;
	public static DBLocalCallQueue DBLocalCalls;
	private static boolean powershellMode = false;
	
	public static void main(String args[]) {
		
		if (args.length >= 4) {
		
			ConfigManager.loadProperties(args[1],false);
			
			String logFile = ConfigManager.getProperty("app.main.homedir")+ConfigManager.getProperty("app.main.logdir")+args[3];
			
			// start the logging based off the log level specified in args[0]
			LOG_FILE = Logging.startLogFile(args[0],logFile);
			
			domain = args[2];
			
			if (args.length == 5) {
				
				if (args[4].equals("POWERSHELL")) {
					powershellMode = true;
				}
			}
			
			initDBQueues();
			
			startProcess();
		}
		
	}
	
	public static boolean getPowershellMode() {
		return powershellMode;
	}
	
	private static void initDBQueues() {
		
		DBLocalCalls = new DBLocalCallQueue();
		PAWSInstaller.LOG_FILE.log(Level.ALL,"DBLocalCalls creation: "+DBLocalCalls);
	}

	public static String getDomain() {;
		return domain;
	}
	
	private static void startProcess() {
		
		new ProcessInstallRequests();
	}
}
